import getsqlline from "../mysql/mysqllines";
import { dosql } from "../tool/sqlTool";
import { Blog } from "../tool/varType";
// 保存博客
export async function addblogData(blog: Blog) {
  return dosql(
    `insert into blogs (uid,title,introduction,content,blog_type,img,blog_tag,read_,create_time,blog_id,author) 
    values (?,?,?,?,?,?,?,?,now(),uuid(),?) `,
    [
      blog.uid,
      blog.title,
      blog.introduction,
      blog.content,
      blog.blog_type,
      blog.img,
      blog.blog_tag,
      blog.read_,
      blog.author,
    ]
  );
}
//读取博客
export async function readBlogdata(page: number) {
  return dosql(
    `select * from blogs order by create_time  Asc limit ${(page - 1) * 10},10`,
    []
  );
}
// 查询数据总条数
export async function getDataTotal() {
  return dosql(`select count(*) as total from blogs`, []);
}
// 删除博客
export async function delblog(id: string) {
  console.log(id);

  return dosql(`delete from blogs where id=${id} `, []);
}
// 删除博客
export async function getDetail(id: string) {
  return dosql(` select * from blogs where id=${id} `, []);
}
// 更新博客
export async function updateBlog(blog: Blog) {
  return dosql(
    `update blogs set title=?,introduction=?,content=?,blog_type=?,img=?,blog_tag=?,read_=? where id=?`,
    [
      blog.title,
      blog.introduction,
      blog.content,
      blog.blog_type,
      blog.img,
      blog.blog_tag,
      blog.read_,
      blog.id,
    ]
  );
}
export async function getTypeBlog(id: string) {
  return dosql(`select * from blogs where blog_type=${id}`, []);
}
export async function getTagBlog(id: string) {
  return dosql(`select * from blogs where blog_tag=${id}`, []);
}
